<template>
	<view class="comment-item">
		<view class="avatar">
			<u-avatar :src="avatar" size="26"></u-avatar>
		</view>

		<view class="wrap">
			<view class="top">
				<view class="username">{{receiveCommentObj.user_id[0].nickname}}</view> <text v-if="isAuthor">作者</text>
			</view>

			<view class="comment-content">{{receiveCommentObj.comment_content}}</view>
			<view class="info">
				<view class="reply-btn" @click="goReply" v-if="replyBtnVbt">
					{{receiveCommentObj.totalReply||''}} 回复
				</view>
				<view>
					<uni-dateformat :date="receiveCommentObj.comment_date" :threshold="[60000,3600000*24*30]">
					</uni-dateformat>
				</view>
				<view>{{receiveCommentObj.province}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "comment-item",
		props: {
			receiveCommentObj: {
				type: Object,
				default () {
					return {}
				}
			},
			// 当前查看文章的发布者的id
			userId: {
				type: String,
				default: ''
			},

			replyBtnVbt: {
				type: Boolean,
				default: false
			},
		},
		computed: {
			avatar() {
				return this.receiveCommentObj.user_id[0]?.avatar_file?.url
			},
			isAuthor() {
				return this.receiveCommentObj.user_id[0]._id == this.userId
			}
		},
		data() {
			return {

			};
		},
		methods: {
			goReply() {

				uni.setStorageSync('temp-comment', this.receiveCommentObj)
				uni.navigateTo({
					url: "/pages/reply/reply"
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.comment-item {
		display: flex;

		.wrap {
			flex: 1;
			padding-left: 20rpx;
			padding-bottom: 20rpx;

			.top {
				display: flex;
				align-items: center;

				text {
					margin-left: 8rpx;
					padding: 8rpx;
					// border: 1px solid #5c6bc0;
					// border-radius: 8rpx;
					// border-color: #5c6bc0;
					font-size: 24rpx;
					color: #fff;
					background-color: #5c6bc0;
				}
			}

			.username {
				font-size: 26rpx;
				color: #666;
				padding: 10rpx 0;
			}

			.comment-content {
				font-size: 34rpx;
				color: #111;
				line-height: 1.8em;
			}

			.info {
				font-size: 26rpx;
				color: #666;
				display: flex;
				padding: 10rpx 0;
				align-items: center;

				view {
					margin-right: 25rpx;
				}

				.reply-btn {
					padding: 6rpx 18rpx;
					background: #e4e4e4;
					border-radius: 30rpx;
				}
			}
		}
	}
</style>